<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Model;

use Hyperf\DbConnection\Model\Model;

class CustomerPermissions extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'customer_permissions';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = [
        'id', 'permission_name', 'parent_id', 'route', 'icon', 'module', 'permission_mark', 'type', 'active_menu', 'component',
        'redirect', 'hidden', 'keepalive', 'creator_id', 'sort', 'created_at', 'updated_at', 'deleted_at', 'my_type'
    ];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'created_at' => 'integer', 'updated_at' => 'integer'];

    protected string $primaryKey = 'id';
    protected ?string $dateFormat = 'U';

    const TOP_MENU = 1;
    const MENU = 2;
    const ACTION_MENU=3;

    public function actions()
    {
        return $this->hasMany(self::class, 'parent_id', 'id')->where('type', self::ACTION_MENU);
    }

    public function getCreatedAtAttribute($value)
    {
        return $value ? date('Y-m-d H:i:s', intval($value)) : '';
    }

    public function getUpdatedAtAttribute($value)
    {
        return $value ? date('Y-m-d H:i:s', intval($value)) : '';
    }
}
